package com.example.recipesapp.ui.screens

import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.example.recipesapp.data.Recipe
import com.example.recipesapp.data.Step
import com.example.recipesapp.ui.components.StepItem

@Composable
fun RecipeDetailDialog(recipe: Recipe, steps: List<Step>, onDismiss: () -> Unit) {
    AlertDialog(
        onDismissRequest = onDismiss,
        title = { Text(recipe.name) },
        text = {
            // 内容滚动
            // 使用 Modifier.verticalScroll(rememberScrollState()) 避免长内容溢出屏幕
            // 响应式布局
            // 通过 Modifier.widthIn(min=200.dp, max=400.dp) 控制弹窗宽度
            LazyColumn(Modifier
                .verticalScroll(rememberScrollState())
                .widthIn(min = 200.dp, max = 400.dp)) {
                item { Text("合计： ${recipe.ingredients}") }
                items(steps) { step ->
                    StepItem(step)
                }

            }
        },
        confirmButton = {
            Button(onClick = onDismiss) {
                // 视觉层次
                Text(
                    "关闭",
                    style = MaterialTheme.typography.headlineSmall,
                    color = MaterialTheme.colorScheme.primary
                )
            }
        }
    )

}


// 完全自定义Dialog（灵活控制）
//import androidx.compose.ui.window.Dialog
//
//@Composable
//fun RecipeDetailDialog(recipe: Recipe, steps: List<Step>, onDismiss: () -> Unit) {
//    Dialog(onDismissRequest = onDismiss) {
//        Card(
//            shape = MaterialTheme.shapes.extraLarge,
//            modifier = Modifier
//                .fillMaxWidth(0.9f)
//                .verticalScroll(rememberScrollState())
//        ) {
//            Column(Modifier.padding(24.dp)) {
//                Text(recipe.name, style = MaterialTheme.typography.headlineSmall)
//                Spacer(Modifier.height(16.dp))
//                Text("合计：${recipe.ingredients}")
//
//                // 步骤列表
//                steps.forEach { step ->
//                    StepItem(step)
//                }
//
//                Spacer(Modifier.height(24.dp))
//                Button(
//                    onClick = onDismiss,
//                    modifier = Modifier.align(Alignment.End)
//                ) {
//                    Text("关闭")
//                }
//            }
//        }
//    }
//}